package com.itheima.practice02;
//HashSet集合存储学生对象并遍历

import java.util.HashSet;
import java.util.Iterator;

public class HashSetTest {
    public static void main(String[] args) {
        HashSet<Student> hashSet = new HashSet<Student>();

        Student student1 = new Student("八戒", 80, 90, 100);
        Student student2 = new Student("八戒", 80, 90, 100);
        Student student3 = new Student("悟空", 98, 76, 90);
        Student student4 = new Student("三藏", 80, 89, 97);
        Student student5 = new Student("沙和尚", 94, 88, 90);
        Student student6 =  new Student("白骨精", 90, 90, 100);

        hashSet.add(student1);
        hashSet.add(student2);
        hashSet.add(student3);
        hashSet.add(student4);
        hashSet.add(student5);
        hashSet.add(student6);
        //用迭代器遍历
        Iterator<Student> iterator = hashSet.iterator();
        while (iterator.hasNext()){
            Student next = iterator.next();
            System.out.println(next);
        }
        System.out.println("===========================");
        //用增强For遍历
        for (Student student : hashSet) {
            System.out.println(student);
        }
        System.out.println("===========================");
        //用foreach遍历
        hashSet.forEach(student -> {
            System.out.println(student);
        });
    }
}
